<template>
  <div class="page-container">
    <ex_super_table_page v-bind="option" ref="SuperTablePage">
    </ex_super_table_page>
    <ex_super_dialog_form ref="formDialog" :title="dialogTitle" v-bind="dialog"
      @afterSubmitSuccess="$refs['SuperTablePage'].reload()">

    </ex_super_dialog_form>
  </div>
</template>
<script>
import business_function from "@/common/business_function"

import superTablePageFunction from '@/mixin/super-table-page-function';

export default {
  title: 'label_anomaly_desc',
  mixins: [superTablePageFunction],
  components: {},
  data() {
    return {
      option: {
        search: {
          model: [
            {
              key: 'anomalyClassifyId', label: 'label_anomaly_class', type: 'select',
              attrs: {
                url: '/oms-api/anomaly/OmsBaseAnomalyClassifyRpc/selectAll.json',
                option: { label: 'name', value: 'id' }
              },
            },
            { key: 'isEnable', label: 'label_isEnable', type: 'select', enum: 'YesOrNoEnum', },
            { key: 'scence', label: 'label_scene_desc', },
            { key: 'processNodeList', label: 'label_process_node',type: 'select', multiple:true, enum:'AbnormaProcessNodeEnum' },

          ],
        },
        action: [
          {
            label: { _key: "label_new_any",i18n: true, type: 'label_anomaly_desc' }, attrs: { icon: "el-icon-plus" },
            auth:"oms_anomaly_desc_edit",
            click: () => {
              this.dialogTitle = this.$tt({ _key: "label_new_any", i18n: true,type: 'label_anomaly_desc' })
              this['$refs']['formDialog'].show(null, { setData: true })
            }
          },
        ],
        actionExtra: [

          {
            label: 'label_export', auth:'oms_anomaly_desc_export', click: this.exportExcel
          },

        ],
        table: {
          url: "/oms-api/anomaly/OmsBaseAnomalyDescribeRpc/selectPage.json",
          model: [
            { key: 'name', label: 'label_name', 'min-width': 200, 'show-overflow-tooltip': true, },
            { key: 'anomalyClassifyName', label: 'label_anomaly_class', 'width': 160, 'show-overflow-tooltip': true, },
            { key: 'scence', label: 'label_scene_desc', 'width': 160, 'show-overflow-tooltip': true, },
            {
              key: 'processNode', label: 'label_process_node', 'width': 140, 'show-overflow-tooltip': true,
              formatter: (r, c, v, i) => this.$enumShow(v, "AbnormaProcessNodeEnum")
            },
            {
              key: 'isDefault', label: 'label_is_default_node', 'width': 120, 'show-overflow-tooltip': true,
              formatter: (r, c, v, i) => this.$enumShow(v, "YesOrNoEnum")
            },

            { key: 'remark', label: 'label_remark', 'min-width': 200, 'show-overflow-tooltip': true, },
            {
              key: 'isEnable', label: 'label_isEnable', 'width': 120, 'show-overflow-tooltip': true,
              formatter: (r, c, v, i) => this.$enumShow(v, "YesOrNoEnum")
            },
            {
              type: 'operate', width: 160, operate: [
                {
                  label: 'label_edit',
                  auth:'oms_anomaly_desc_edit',
                  disabled: (row) => {
                    return row.isDefault == 'Y'
                  }, click: (row) => {
                    this.dialogTitle = this.$tt({ _key: 'label_edit_any',i18n: true, type: 'label_anomaly_desc' })
                    this['$refs']['formDialog'].show(row, { setData: true })
                  }
                },
                {
                  label: 'label_start_using', type: "confirm-button", url: '/oms-api/anomaly/OmsBaseAnomalyDescribeRpc/updateEnableStatus.json', message: 'label_sure_to_enable_this',
                  buttonClass: "button_text_success", confirmButtonType: 'success',
                  urlType: 'json',
                  auth:'oms_anomaly_desc_edit',
                  if: (row) => row.isEnable == 'N' ,
                  disabled: (row) => {
                    return row.isDefault == 'Y'
                  },
                  params: (row) => {
                    return { id: row["id"], isEnable: 'Y' }
                  }, done: ['tip', 'reload']
                },
                {
                  label: 'label_disable_using', type: "confirm-button", url: '/oms-api/anomaly/OmsBaseAnomalyDescribeRpc/updateEnableStatus.json', message: 'label_tms_confirm_stop',
                  buttonClass: "button_text_danger", confirmButtonType: 'danger',
                  urlType: 'json',
                  auth:'oms_anomaly_desc_edit',
                  if: (row) => row.isEnable == 'Y' ,
                  disabled: (row) => {
                    return row.isDefault == 'Y'
                  },
                  params: (row) => {
                    return { id: row["id"], isEnable: 'N' }
                  }, done: ['tip', 'reload']
                },
                {
                  disabled: (row) => {
                    return row.isDefault == 'Y'
                  },
                  auth:'oms_anomaly_desc_delete',
                  label: 'label_delete',
                  type: "confirm-button",
                  url: '/oms-api/anomaly/OmsBaseAnomalyDescribeRpc/remove.json',
                  message: 'text_confirm_sure_delete',
                  buttonClass: "button_text_danger",
                  confirmButtonType: 'danger',
                  params: (row) => {
                    return { "id": row["id"] }
                  },
                  done: ['reload', 'tip']
                }
              ]
            }
          ],
        }
      },

      dialogTitle: '',
      dialog: {
        customClass: 'dialog_auto',
        submitUrl: '/oms-api/anomaly/OmsBaseAnomalyDescribeRpc/saveOrUpdate.json',
        form: {
          itemClass: "form_item_default", inputClass: "form_input_default",
          default: { isEnable: 'Y' },
          model: [
            { header: "label_base_info", },
            {
              key: 'anomalyClassifyId', label: 'label_anomaly_class', type: 'select', attrs: {
                url: '/oms-api/anomaly/OmsBaseAnomalyClassifyRpc/selectAll.json',
                option: { label: 'name', value: 'id' }
              }, keyExtra: { name: 'anomalyClassifyName' },
            },
            { key: 'name', label: 'label_name', attrs: { maxlength: 50, 'show-word-limit': true } },

            { key: 'scence', label: 'label_scene_desc', attrs: { maxlength: 50, 'show-word-limit': true } },
            { key: 'processNode', label: 'label_process_node', type: 'select', attrs: { enum: 'AbnormaProcessNodeEnum', } },
            { key: 'remark', label: 'label_remark', attrs: { type: 'textarea', autosize: { minRows: 2, maxRows: 6 }, maxlength: 200, 'show-word-limit': true } },
          ],
          rules: {
            'anomalyClassifyId': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            'name': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            'scence': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            'processNode': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            'remark': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
          },
        }
      },
    };
  },
  methods: {

    exportExcel() {
      business_function.confirmOperateBaseSelectOrForm.call(this, {
        data: this.$refs.SuperTablePage.getSearchFormData(),
        model: this.option.search.model,
        callback: (selection, data) => {
          let params = data
          this.$functionCommon({
            url: "/oms-api/anomaly/OmsBaseAnomalyDescribeRpc/export.json",
            data: params, type: 'form',
          })
        }
      })

    },
  }
};

</script>
<style></style>
